package com.web.controller.rest;

import com.core.model.user.User;
import com.service.user.AdministratorService;
import com.exception.AdminNotFoundException;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * User: xf
 * Date: 2016/5/6
 * Time: 22:11
 * To change this template use Editor | File and Code Templates.
 */
@RestController
@RequestMapping("/rest")
@Api(value = "/rest", description = "restful相关入口")
public class RestfulApiController {

    @Autowired
    private AdministratorService administratorService;

    @ApiOperation(value = "查看用户", notes = "根据用户名查看用户", httpMethod = "GET", code = 200,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String", paramType = "path")
    @ResponseStatus(HttpStatus.OK)
    @RequestMapping(value = "user/{username}", method = RequestMethod.GET)
    public User findUserByUsername(@PathVariable String username) {
        User user = administratorService.findAdminByUsername(username);
        if (user == null) {
            throw new AdminNotFoundException(username);
        }
        return user;
    }

}
